#ifndef _CPP_STORY_TABLE_H_
#define _CPP_STORY_TABLE_H_

#include <map>
#include <string>
#include <vector>
#ifdef WIN32
#include "cppstory_win32.h"
#endif

namespace CppStory
{

#ifdef WIN32
class CPPSTORY_WIN32_API Table
#else
class Table
#endif
{
public:
    Table();
    void set_str(std::string s);
    const char* get_str() { return table_str.c_str(); }
    void parse();
    int get_row_count() { return row_count; }
    int get_col_count() { return col_count; }
    std::string get_head_name(int index) { return heads[index]; }
    std::string get_data(int row, int col) { return data[get_head_name(col)][row]; }
private:
    std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems);
    std::vector<std::string> split(const std::string &s, char delim);
    std::string trim(std::string& str);
    void clear();

    std::string table_str;
    std::vector <std::string> heads;
    std::map <std::string, std::vector <std::string> > data;
    int row_count;
    int col_count;
};

}

#endif

